package com.tct.worktimeboard.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tct.worktimeboard.entity.WorkTask;
import com.tct.worktimeboard.mapper.WorkTaskMapper;
import com.tct.worktimeboard.service.IWorkTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tct.worktimeboard.util.JsonUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liyongkui
 * @since 2021-02-24
 */
@Service
public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTask> implements IWorkTaskService {
    @Resource
    WorkTaskMapper workTaskMapper;

    @Override
    public JSONObject getWorkTaskList(WorkTask workTask) {
        QueryWrapper<WorkTask> queryWrapper = new QueryWrapper<>();
        if(workTask.getTaskName() != null && !workTask.getTaskName().isEmpty()){
            queryWrapper.like("task_name",workTask.getTaskName());
        }
        if(workTask.getProjectId() != null){
            queryWrapper.eq("project_id",workTask.getProjectId());
        }
        if(!workTask.isPaged()){
            workTask.setPageNum(1);
            workTask.setPageSize(10);
        }
        Page<WorkTask> page = new Page<>(workTask.getPageNum(),workTask.getPageSize());
        return JsonUtil.toJsonData(workTaskMapper.selectPage(page,queryWrapper));
    }
}
